//
//  SubscribeQYCell.swift
//  NDAi
//
//  Created by 丸子 on 2024/6/20.
//

import UIKit

class SubscribeQYCell: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource {
 
    let titleArr:[String] = ["上下文对话", "工作帮手", "AI创作", "AI绘画"]
    let imageArr:[String] = [ "icon_mine_msg", "icon_mine_gz", "icon_mine_ai", "icon_mine_hh"]
    
    private lazy var collectionView: UICollectionView = {
        let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .horizontal
        let height = (SCREEN_WIDTH - 58) / 4
        layout.itemSize = CGSize(width: Int(height), height: Int(height + 22))
        layout.sectionInset = UIEdgeInsets(top: 0, left: 14, bottom: 0, right: 14)
        // 设置每行的项目数量
        let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.register(cellWithClass: SubscribeQYCollectionViewCell.self)
        collectionView.backgroundColor = UIColor.clear // 设置背景颜色
        collectionView.showsVerticalScrollIndicator = false
        collectionView.showsHorizontalScrollIndicator = false
        return collectionView
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = .clear
        self.contentView.addSubview(collectionView)
        let height = (SCREEN_WIDTH - 88) / 4
        collectionView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
            make.height.equalTo(height + 22)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.titleArr.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let title = self.titleArr[indexPath.item]
        let image = self.imageArr[indexPath.item]
        let cell = collectionView.dequeueReusableCell(withClass: SubscribeQYCollectionViewCell.self, for: indexPath)
        cell.iconIV.image = UIImage(named: image)
        cell.lockLb.text = title
        return cell
    }
}


class SubscribeQYCollectionViewCell: UICollectionViewCell {
     lazy var iconIV: UIImageView = {
       let imageView = UIImageView()
        imageView.image = UIImage(named: "icon_mine_gpt4")
        imageView.contentMode = .scaleToFill
        imageView.clipsToBounds = true
        return imageView
    }()
    
     lazy var lockLb: UILabel = {
       let label = UILabel()
        label.textColor = Theme.color.text_d3
        label.font = UIFont.pingFangSCRegular(ofSize: 14)
        label.textAlignment = .center
        label.text = "GPT4.0"
        return label
    }()
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = .clear
        self.addSubviews([iconIV, lockLb])
        iconIV.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(4)
            make.centerX.equalToSuperview()
            make.width.height.equalTo(50)
        }
        lockLb.snp.makeConstraints { make in
            make.top.equalTo(iconIV.snp.bottom).offset(8)
            make.leading.trailing.equalToSuperview()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
}
